package org.liuwei.concucrent.base02_cas.UnsafeArrayList_08;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 
 * @Title: UnsafeArrayList.java
 * @Package org.liuwei.concucrent.base10
 * @Description: TODO(测试非线程安全的ArrayList)
 * @author 刘伟 15818570028@163.com
 * @date 2016年8月20日 下午12:19:22
 * @version V1.0
 */
public class UnsafeArrayList {
	ArrayList al = new ArrayList();
	Map m = new HashMap();

	public static void main(String[] args) throws InterruptedException {
		new UnsafeArrayList().test();
	}

	public void test() throws InterruptedException {
		
		
		Thread t1 = new Thread(new AddTask(), "t1");
		Thread t2 = new Thread(new AddTask(), "t2");
		Thread t3 = new Thread(new AddTask(), "t3");
		Thread t4 = new Thread(new AddTask(), "t3");
		Thread t5 = new Thread(new AddTask(), "t3");
		t1.start();
		t2.start();
		t3.start();
		t4.start();
		t5.start();
		t1.join();
		t2.join();
		t3.join();
		t4.join();
		t5.join();
        System.err.println(m.size());
        m.forEach((k,v)->{System.out.println(k+"============="+v);});
        System.out.println(111);
	}

	class AddTask implements Runnable {
		public void run() {
			for (int i = 0; i < 1000; i++) {
//				al.add(i);
//				m.put("dd, value)
				 m.put("i"+i, "i"+i);
			}

		}
	}

}